package org.tigris.elfin;

import java.lang.reflect.*;

public class BeanCapturer {
	public static String getValue(String name, Object obj) {
		/*
		 * int dot = name.lastIndexOf('.'); if (dot > 0) { name =
		 * name.substring(dot + 1, name.length()); } else { return null; }
		 */try {
			Class[] params = new Class[] {};
			String getter = "get" + Character.toUpperCase(name.charAt(0))
					+ name.substring(1, name.length());
			System.out.println("getter: " + getter);

			Method method = obj.getClass().getMethod(getter, params);
			return String.valueOf(method.invoke(obj, new Object[] {}));
		} catch (NoSuchMethodException ex) {
			ex.printStackTrace();
		} catch (IllegalAccessException ex) {
			ex.printStackTrace();
		} catch (InvocationTargetException ex) {
			ex.printStackTrace();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return "0";
	}
}
